# -*- coding:UTF-8 -*-

import BeautifulReport
import unittest, time
import sys,os


casedata = sys.path[0]
# print(casedata)
resultsPath = sys.path[0] +'/result/'
# print(resultsPath)
def Creatsuite():
    # 定义单元测试容器
    testunit = unittest.TestSuite()
    #定搜索用例文件的方法
    discover = unittest.defaultTestLoader.discover(casedata+'/base', pattern='test*.py', top_level_dir=None)

    #将测试用例加入测试容器中
    for test_suite in discover:
        for casename in test_suite:
            testunit.addTest(casename)
    return testunit

if __name__ == '__main__':
    test_case = Creatsuite()
    # 获取系统当前时间
    unittest.TextTestRunner(verbosity=2).run(test_case)
'''
    now = time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime(time.time()))
    #定义个报告存放路径，支持相对路径
    filename =  now + 'XXXXWEBUI测试报告'
    if not os.path.exists(resultsPath):
        os.mkdir(resultsPath)
    runner = BeautifulReport.BeautifulReport(test_case)
    #运行测试用例
    # print(resultsPath)
    runner.report(filename=filename, description='测试结果',log_path=resultsPath)
'''